<?php


namespace app\api\library;
use app\common\model\UserMoneyLog as LogModel;


class UserMoneyLog
{
    const SHARE_USER_ORDER = 1;
    const SHARE_USER_ORDER_FINISH = 2;
    const PAYMENT = 3;
    const WITHDRAW = 4;

    /**
     * 收入
     */
    public static function income($userId, $type, $fromUserId, $fromOrderId, $money, $userMoney, $memo)
    {
        $data = [
            'user_id' => $userId,
            'type' => $type,
            'from_user_id' => $fromUserId,
            'from_order_id' => $fromOrderId,
            'money' => $money,
            'before' => $userMoney,
            'after' => bcadd($money, $userMoney, 2),
            'memo' => $memo,
        ];
        LogModel::create($data);
    }

    /**
     * 支出
     */
    public static function expend($userId, $type, $fromUserId, $fromOrderId, $money, $userMoney, $memo)
    {
        $data = [
            'user_id' => $userId,
            'type' => $type,
            'from_user_id' => $fromUserId,
            'from_order_id' => $fromOrderId,
            'money' => $money,
            'before' => $userMoney,
            'after' => bcsub($userMoney, $money, 2),
            'memo' => $memo,
        ];
        LogModel::create($data);
    }
}